<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
      xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
      layout:decorate="~{layout/default}">
<head>
    <title>编辑联系人</title>
</head>
<body>
    <div layout:fragment="content">
        <div class="d-flex justify-content-between align-items-center mb-3">
            <h1>编辑联系人</h1>
            <a th:href="@{/contact/list}" class="btn btn-secondary">返回列表</a>
        </div>
        
        <div class="card">
            <div class="card-body">
                <form id="contactForm" data-validate="true" data-redirect="/crm/contact/list">
                    <input type="hidden" name="id" th:value="${contact.id}">
                    
                    <div class="row">
                        <div class="col-md-6">
                            <div class="form-group">
                                <label for="name">姓名</label>
                                <input type="text" class="form-control" id="name" name="name" th:value="${contact.name}" required>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="form-group">
                                <label for="phone">电话</label>
                                <input type="text" class="form-control" id="phone" name="phone" th:value="${contact.phone}" required>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="form-group">
                                <label for="email">电子邮箱</label>
                                <input type="email" class="form-control" id="email" name="email" th:value="${contact.email}">
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="form-group">
                                <label for="position">职位</label>
                                <input type="text" class="form-control" id="position" name="position" th:value="${contact.position}">
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="form-group">
                                <label for="customerId">所属客户</label>
                                <input type="hidden" name="customerId" th:value="${contact.customerId}">
                                <input type="text" class="form-control" id="customerName" name="customerName" th:value="${contact.customerName}" readonly>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="form-group">
                                <label>是否主要联系人</label>
                                <div>
                                    <div class="form-check form-check-inline">
                                        <input class="form-check-input" type="radio" name="isPrimary" id="isPrimaryYes" value="true" th:checked="${contact.isPrimary}">
                                        <label class="form-check-label" for="isPrimaryYes">是</label>
                                    </div>
                                    <div class="form-check form-check-inline">
                                        <input class="form-check-input" type="radio" name="isPrimary" id="isPrimaryNo" value="false" th:checked="${!contact.isPrimary}">
                                        <label class="form-check-label" for="isPrimaryNo">否</label>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="col-md-12">
                            <div class="form-group">
                                <label for="remark">备注</label>
                                <textarea class="form-control" id="remark" name="remark" rows="3" th:text="${contact.remark}"></textarea>
                            </div>
                        </div>
                    </div>
                    
                    <div class="text-right">
                        <button type="submit" class="btn btn-primary">保存</button>
                        <a th:href="@{/contact/list}" class="btn btn-secondary ml-2">取消</a>
                    </div>
                </form>
            </div>
        </div>
    </div>
    
    <th:block layout:fragment="scripts">
        <script>
            document.addEventListener('DOMContentLoaded', function() {
                // 初始化表单提交
                submitForm('contactForm', '/crm/api/contact/update');
            });
        </script>
    </th:block>
</body>
</html> 